﻿/*!	r_draw_inputlayout_desc.cpp
	@brief	頂点レイアウト
Copyright (c) 2010 Yuya Yamaguchi

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

#include "r_draw_inputlayout_desc.h"
#include "../util/r_util_str.h"
#include "r_draw_core.h"
#include "r_draw_allocator.h"

namespace r{
	namespace draw{
		InputLayoutDescAttr :: InputLayoutDescAttr ( const r_mstr _semanticName, r_ui32 _format, r_ui32 _offset, r_ui32 _semanticIndex, r_ui32 _slotIndex )
			:
			semanticNameM ( _semanticName ),
			format ( _format ),
			offset ( _offset ),
			semanticIndex ( _semanticIndex ),
			slotIndex ( _slotIndex )
		{
			r_wchar	convBuffer[512];
			fRStrMultiToWide ( convBuffer, _semanticName, 512 );
			semanticNameW = convBuffer;
		}

		InputLayoutDescAttr :: InputLayoutDescAttr ( const r_wstr _semanticName, r_ui32 _format, r_ui32 _offset, r_ui32 _semanticIndex, r_ui32 _slotIndex )
			:
			semanticNameW ( _semanticName ),
			format ( _format ),
			offset ( _offset ),
			semanticIndex ( _semanticIndex ),
			slotIndex ( _slotIndex )
		{
			r_mchar	convBuffer[512];
			fRStrWideToMulti ( convBuffer, _semanticName, 512 );
			semanticNameM = convBuffer;
		}

		InputLayoutDescAttr :: ~InputLayoutDescAttr()
		{
		}

		const r_mstr	InputLayoutDescAttr :: getSemanticNameM() const
		{
			return semanticNameM.c_str();
		}

		const r_wstr	InputLayoutDescAttr :: getSemanticNameW() const
		{
			return semanticNameW.c_str();
		}

		r_ui32	InputLayoutDescAttr :: getFormat() const
		{
			return format;
		}

		r_ui32	InputLayoutDescAttr :: getOffset() const
		{
			return offset;
		}

		r_ui32	InputLayoutDescAttr :: getSemanticIndex() const
		{
			return semanticIndex;
		}

		r_ui32	InputLayoutDescAttr :: getSlotIndex() const
		{
			return slotIndex;
		}


///////////////////////////////////////////////////////

		RALLOC_PLACEMENT_NEW_DELETE_IMPLEMENT( r::draw::InputLayoutDesc, r::draw::AllocatorData()() )


		InputLayoutDesc :: InputLayoutDesc()
		{
		}

		InputLayoutDesc :: ~InputLayoutDesc()
		{
		}

		void	InputLayoutDesc :: add ( const InputLayoutDescAttr& attr )
		{
			vertexLayout.push_back ( attr );
		}

		r_size	InputLayoutDesc :: getAttrNum() const
		{
			return vertexLayout.size();
		}

		const InputLayoutDescAttr*	InputLayoutDesc :: getAttr ( r_ui32 index ) const
		{
		#ifdef R_DRAW_MOREDEBUG
			RDEBUG_ASSERT ( index < getAttrNum() )
		#endif
			return &vertexLayout[index];
		}
	}
}



